import Vue from "vue";
import Vuex from "vuex";
import Cache from "../common/cache"
Vue.use(Vuex);
const store = new Vuex.Store({
    state: {
        token:Cache.getCache("token"),
        userInfo:Cache.getCache("userInfo")
    },
    mutations: {
        setToken(state,payload) {
            state.token = payload.token
            Cache.setCache("token", payload.token)
            console.log(Cache.getCache("token"))
        },
        setUserInfo(state, payload) {
            state.userInfo = payload.userInfo
            Cache.setCache("userInfo",payload.userInfo)
        },
        clear(state) {
            state.userInfo = {}
            state.token=""
            console.log(state)
        }
    },
    actions: {
        // addCart(context, payload) {
        //     let oldProduct = context.state.CartList.find(item => item.iid == payload.iid);
        //     if (oldProduct) {
        //         context.commit("addOldCart", oldProduct);
        //     } else {
        //         context.commit("addNewCart", payload);
        //     }
        // },

    }
})
export default store